<?PHP
require_once('config.inc.php');
require_once('database.inc.php');
require_once('functions.inc.php');
require_once(LIBRARY_PATH.'json/JSON.php');
require('security.php');

$db = LinkDB();
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);

//检查权限
if (!findPopedom('linkman', 'edit')) feedback(false, '[没有进行此操作的权限]');

$id = @$_GET['id'];
$basic = $db->GetRow('SELECT * FROM people WHERE id = ?', $id);
if (!$basic) feedback(false, '[找不到指定的联系人信息]');
$orderString = ' ORDER BY name';
$contact = $db->GetAll('SELECT * FROM contactinfo WHERE fatherid = ?'.$orderString, $id);
$customData = array();
if ($contact) {
	foreach ($contact as $item) {
		$customData[] = array('id'     => $item['id'],
							  'title'  => $item['name'],
							  'content'=> $item['content']);
	}
}
/**
 * 数据信息模板
{
	'basicData'	: {
		'name':'联系人姓名',
		'birthday':'2007-05-19',
		'sex':'男'
	},

	'customData'	: [
		{'id':'21',
		 'title':'手机号',
		 'content':'12345678901'},
		{'id':'22',
		 'title':'座机号码',
		 'content':'010-00000000'}
	],

	'remarkData'	:{
		'content':'默认备注'
	}
}
*/
$result = array(
    'isSucceed'=> true,
    'data'     => array(
	    'basicData' => array(
	        'name'    => $basic['name'],
	        'birthday'=> $basic['birthday'],
	        'sex'     => $basic['sex']
	    ),
	    'customData'=> $customData,
	    'remarkData'=> array(
	        'content'=> $basic['remark']
	    )
    )
);
echo $json->encode($result);
?>